<?php
namespace app\admin\controller;

use app\common\cache\loan\ILoanCache;
use app\common\cache\user\IUserCache;
use app\common\controller\AdminBaseController;
use app\common\enum\IsDelete;
use app\common\ext\IDb;
use app\common\ext\IRequest;
use think\Db;

class LoanFavorite extends AdminBaseController{

    /**
     * @功能：贷款产品收藏
     * @开发者：cxl
     * @return string
     */
    public function loan_favorite_list(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $loan_product_id = IRequest::get("loan_product_id");

        //取得数据
        $where['is_delete'] = IsDelete::No;
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($loan_product_id)) $where['loan_product_id'] = $loan_product_id;
        $loan_favorite_list = IDb::getInstance("loan_favorite")
            ->setDbWhere($where)
            ->setDbOrder('loan_favorite_id desc')
            ->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("loan_product_id",$loan_product_id);
        $this->assign("loan_favorite_list",$loan_favorite_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：贷款产品收藏
     * @开发者：cxl
     * @return string
     */
    public function loan_favorite_del_list(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $loan_product_id = IRequest::get("loan_product_id");

        //取得数据
        $where['is_delete'] = IsDelete::Yes;
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($loan_product_id)) $where['loan_product_id'] = $loan_product_id;
        $loan_favorite_list = IDb::getInstance("loan_favorite")
            ->setDbWhere($where)
            ->setDbOrder('loan_favorite_id desc')
            ->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("loan_product_id",$loan_product_id);
        $this->assign("loan_favorite_list",$loan_favorite_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：贷款产品收藏详情
     * @开发者：cxl
     * @return string
     */
    public function loan_favorite_info(){
        //接收参数
        $loan_favorite_id = IRequest::get("loan_favorite_id",IRequest::NOT_EMPTY,"贷款产品收藏编码不能为空！");

        //贷款产品收藏详情
        $where = null;
        $where['loan_favorite_id'] = $loan_favorite_id;
        $loan_favorite_info = IDb::getInstance("loan_favorite")->setDbWhere($where)->row();
        if($loan_favorite_info === false){
            error("取得贷款产品收藏信息失败！");
        }

        //贷款产品收藏详情
        $user_info = IUserCache::getInfo($loan_favorite_info['user_id']);
        if($user_info === false){
            error("取得贷款产品收藏信息失败！");
        }

        //贷款产品收藏详情
        $loan_product_info = ILoanCache::getInfo($loan_favorite_info['loan_product_id']);
        if($loan_product_info === false){
            error("取得贷款产品收藏信息失败！");
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("loan_favorite_info",$loan_favorite_info);
        $this->assign("user_info",$user_info);
        $this->assign("loan_product_info",$loan_product_info);

        //渲染模板输出
        return view();
    }
}
